import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 能源使用信息 */
export interface EnergyUsage {
          id: number; // 用电记录ID
          dormitoryId?: number; // 宿舍ID
          energyId?: number; // 能源编号
          preReadingDate?: string | Dayjs; // 上次抄表日期
          currentReading?: number; // 当前读数
          previousReading?: number; // 上次读数
          userId: number; // 抄表人
          usage?: string; // 用量
  }

// 能源使用 API
export const EnergyUsageApi = {
  // 查询能源使用分页
  getEnergyUsagePage: async (params: any) => {
    return await request.get({ url: `/dorm/energy-usage/page`, params })
  },

  // 查询能源使用详情
  getEnergyUsage: async (id: number) => {
    return await request.get({ url: `/dorm/energy-usage/get?id=` + id })
  },

  // 新增能源使用
  createEnergyUsage: async (data: EnergyUsage) => {
    return await request.post({ url: `/dorm/energy-usage/create`, data })
  },

  // 修改能源使用
  updateEnergyUsage: async (data: EnergyUsage) => {
    return await request.put({ url: `/dorm/energy-usage/update`, data })
  },

  // 删除能源使用
  deleteEnergyUsage: async (id: number) => {
    return await request.delete({ url: `/dorm/energy-usage/delete?id=` + id })
  },

  /** 批量删除能源使用 */
  deleteEnergyUsageList: async (ids: number[]) => {
    return await request.delete({ url: `/dorm/energy-usage/delete-list?ids=${ids.join(',')}` })
  },

  // 导出能源使用 Excel
  exportEnergyUsage: async (params) => {
    return await request.download({ url: `/dorm/energy-usage/export-excel`, params })
  },
}